package com.todod.base.module.base.dal.mysql.devicebase;

import java.util.*;

import com.todod.base.framework.common.pojo.PageResult;
import com.todod.base.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.todod.base.framework.mybatis.core.mapper.BaseMapperX;
import com.todod.base.module.base.dal.dataobject.devicebase.DeviceBaseDO;
import org.apache.ibatis.annotations.Mapper;
import com.todod.base.module.base.controller.admin.devicebase.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 仪器型号查看 Mapper
 *
 * @author 超管儿
 */
@Mapper
public interface DeviceBaseMapper extends BaseMapperX<DeviceBaseDO> {

    default PageResult<DeviceBaseDO> selectPage(DeviceBasePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceBaseDO>()
                .eqIfPresent(DeviceBaseDO::getDeviceModeCode, reqVO.getDeviceModeCode())
                .eqIfPresent(DeviceBaseDO::getType, reqVO.getType())
                .likeIfPresent(DeviceBaseDO::getMode, reqVO.getMode())
                .orderByDesc(DeviceBaseDO::getId));
    }


    /**
     * 获取仪器型号列表信息
     **/
    @Select("<script>" +
            "SELECT db.device_mode_code , db.type ,db.factory_code,db.`mode`,db.protocol,db.port,db.ip  " +
            "FROM base_device_base db " +
            "<where>" +
            "    db.deleted = 0 " +
            "    <if test='mode != null and mode != \"\"'>" +
            "         AND (db.mode LIKE '%${mode}%') " +
            "    </if>" +
            "    <if test='type != null and type != \"\"'>" +
            "         AND (db.type = #{type}) " +
            "    </if>" +
            "    ORDER BY db.id" +
            "</where>"
            + "</script>")
    public List<DeviceBaseDO> getListDevice(DeviceBaseSaveReqVO reqVO);



    @Select("SELECT COUNT(*) FROM base_device_base WHERE device_mode_code = #{deviceModeCode} AND deleted = 0")
    public int isExist(DeviceBaseDO deviceBaseDO);












}